/*
-----------------------------------------------------------------------------
This source file is part of SapphireEngine

SapphireEngine is a Framework for Turn Based Strategy games.
For more information see http://code.google.com/p/sapphire-engine/

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.

-----------------------------------------------------------------------------
*/
#ifndef _CORE_MANAGER_H
#define _CORE_MANAGER_H

#include <Ogre.h>

#include "SapphirePrerequisites.h"


#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

#include "Core/Technology.h"


namespace SapphireEngine
{
	namespace Core
	{
		/** A Manager class for all Core data.
		@remarks
			SaphireEngine as a framework provides the option to maintain game specific data
			for Terrain and Damage types and a fully customizable Technology tree.
			All relevant data is stored in the mySql database and retrieved at client startup.
		@par
			Connection to mySql is handled with the helper class MySQL_Connection.
			CoreManager uses th writeSql and readSql functions to communicate with the mySql database.
		*/
		class CoreManager : public Ogre::Singleton<CoreManager>
		{
		public:
			CoreManager();
			~CoreManager();
			//mySql
			void writeSql(Ogre::String str);
			sql::ResultSet* readSql(Ogre::String str);
			sql::Connection* getConnection();
			//Terrain
			void addTerrainType(Ogre::String name);
			void removeTerrainType(Ogre::String name);
			const StringSet* getTerrainTypes();
			//Damage
			void addDamageType(Ogre::String name);
			void removeDamageType(Ogre::String name);
			const StringSet* getDamageTypes();
			//Technologies
			void addTechnology(int id, Ogre::String name, int level);
			void removeTechnology(int id);
			void setTechnologyLevel(int id, int level);
			const TechnologyMap* getTechnologies();
			int getTechnologyID(Ogre::String name);
			//Part Types
			void addPartType(Ogre::String name);
			void removePartType(Ogre::String name);
			const StringSet* getPartTypes();
			//Part SubTypes
			void addPartSubType(Ogre::String name);
			void removePartSubType(Ogre::String name);
			const StringSet* getPartSubTypes();
			//Parts
			void addPart(Part *prt);
			void removePart(Part *prt);
			const PartMap* getParts();

			
			long getNextPartID();

			//Accessors
			static CoreManager& getSingleton(void);
			static CoreManager* getSingletonPtr(void);

		protected: //Internal Functions
			//Data Population
			void _getDamageTypes();
			void _getTerrainTypes();
			void _getTechnologies();
			void _getPartTypes();
			void _getSubPartTypes();

		protected: //Member Variables
			StringSet mTerrainTypes; 
			StringSet mDamageTypes;
			TechnologyMap mTechnologies;
			long mPartIDNumbering;
			StringSet mPartTypes;
			StringSet mPartSubTypes;
			PartMap mAvailableParts;
			
			//mySql connection
			sql::Driver *mDriver;
			sql::Connection* mConnection;
			sql::Statement* mStatement;

		}; //class CoreManager
	} //namespace Core
} //namespace SapphireEngine
#endif